/*
 * Stop.java
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.core.transit;

import java.io.Serializable;
import org.fpdev.core.FPEngine;
import org.fpdev.core.basenet.BNode;
import org.fpdev.apps.rtemaster.gui.map.MapCanvas;
import org.fpdev.core.basenet.BaseNetwork;

public abstract class Stop implements Serializable {

  protected transient TransitPath tpath_;

  protected transient BNode node_;
  protected int nodeID_;

  protected String name_;
  protected int inPLI_,  outPLI_; // PLI: Path Link Index
  public final static int STOP_BASIC = 1;
  public final static int STOP_TIMEPOINT = 2;
  public final static int RESTRICTION_NONE = 0;
  public final static int RESTRICTION_BOARD_ONLY = 1;
  public final static int RESTRICTION_ALIGHT_ONLY = 2;

  public Stop(TransitPath tpath, int nodeID, String name, int inPLI, int outPLI) {
    tpath_ = tpath;
    nodeID_ = nodeID;
    name_ = name;
    inPLI_ = inPLI;
    outPLI_ = outPLI;
  }

  public Stop(TransitPath tpath, BNode node, String name, int inPLI, int outPLI) {
    tpath_ = tpath;
    node_ = node;
    nodeID_ = node.getID();
    name_ = name;
    inPLI_ = inPLI;
    outPLI_ = outPLI;
  }

  public void initNode(BaseNetwork baseNet) {
    node_ = baseNet.getNodeFromID(nodeID_);
  }

  /*public void init(TransitPath tpath, FPEngine engine) {
    tpath_ = tpath;
    node_ = engine.getNodeFromID(nodeID_);
  }*/

  public BNode getNode() {
    return node_;
  }

  public int getNodeID() {
    if(node_ != null) return node_.getID();
    return nodeID_;
  }

  public void setNode(BNode node) {
    node_ = node;
    nodeID_ = node.getID();
  }

  public String getName() {
    return name_;
  }

  public void setName(String name) {
    name_ = name;
  }

  public abstract void draw(MapCanvas canvas, int width, boolean annotate);

  public abstract int getType();

  public boolean isTimePoint() {
    return getType() == STOP_TIMEPOINT;
  }

  public int getRestriction() {
    return RESTRICTION_NONE;
  } // overridden by subclasses w/ restriction

  public int getInPLI() {
    return inPLI_;
  }

  public int getOutPLI() {
    return outPLI_;
  }

  public void setPLIs(int inPLI, int outPLI) {
    inPLI_ = inPLI;
    outPLI_ = outPLI;
  }
  //public String getName();
  @Override
  public String toString() {
    return "Stop '" + name_ + " @ node " + node_.getID() + ", inPLI=" + inPLI_ + ", outPLI=" + outPLI_;
  }

  public abstract Stop createCopy(TransitPath newPath);

  public SerializableStop getSerializable() {
    return new SerializableStop(node_.getID(),
            getType(),
            isTimePoint() ? ((TimePoint) this).getName() : "",
            inPLI_,
            outPLI_,
            isTimePoint() ? ((TimePoint) this).getIndex() : 0,
            getRestriction());
  }
}






















